package com.situ.day3;

import org.junit.Test;

import java.util.Random;
import java.util.Scanner;

public class ContinueBreakDemo {
    @Test
    public void rest1(){
        for (int i = 1; i <= 5; i++){
            if(i ==3){
                continue;
            }
            System.out.println(i);
        }
    }

    @Test
    public void test2() {
        for (int i = 1; i <= 5; i++) {
            if (i == 3) {
                break;
            }
            System.out.println(i);
        }
    }

    @Test
    public void  test3(){
        for (int i = 1;i <= 5;i++) {
            System.out.println("i:" + i);
            for (int j = 1; j <= 5; j++){
                if (j  ==  3){
                    break;
                }
                System.out.println("j:"+j);
            }
        }
    }

    //随机生成一个整数1-1000
    @Test
    public void test4() {
        Scanner scanner = new Scanner(System.in);
        Random random = new Random();
        //int valve between zero (inclusive) and bound (exclusive)
        // [0, 1000) + 1
        // [1, 1000]
        int num = random.nextInt(1000) + 1;
        System.out.println("num：" + num);
        //无限循环，死循环 for(;;){}
        while (true) {
            System.out.println("猜吧！");
            int guess = scanner.nextInt();
            if (guess > num){
                System.out.println("太大了");
            } else if (guess < num) {
                System.out.println("太小了");
            } else {
                System.out.println("恭喜你，猜对了");
                break;
            }
        }
    }
}
